home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7134 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to tell if a file exists in C
  5. Date: Fri, 16 Feb 96 17:59:21 GMT
  6. Organization: none
  7. Message-ID: <824493561snz@genesis.demon.co.uk>
  8. References: <4eqkj6$ipo@charm.magnus.acs.ohio-state.edu> <4eqn9q$dr1@sparcserver.lrz-muenchen.de> <3121db3e.43150046@nntp.ix.netcom.com> <4ftpnk$i74@cafu.fl.net.au>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4ftpnk$i74@cafu.fl.net.au> als@fl.net.au "Andrew Snow" writes:
  15.  
  16. >How about plain old:
  17. >
  18. >        if(0==access("filename", F_OK))
  19. >                {
  20. >                do stuff with file();
  21. >                }
  22. >        else
  23. >                {
  24. >                error();
  25. >                }
  26. >
  27. >This works O.K. under Linux and FreeBSD, and most DOS compilers.
  28.  
  29. access() is a specialised function under Unix/POSIX to test permissions
  30. against the real user/group ID's. If you don't want to do that specifically
  31. you should never use access() (and why on other systems you should avoid it
  32. where portability is concerned). stat() is the way to go in that case.
  33.  
  34. However neither of these are as portable as fopen() since that is defined by
  35. the C language.
  36.  
  37. >If you want to see if the file is readable as well as exists,
  38.  
  39. Can a file be readable yet not exist?
  40.  
  41. -- 
  42. -----------------------------------------
  43. Lawrence Kirby | fred@genesis.demon.co.uk
  44. Wilts, England | 70734.126@compuserve.com
  45. -----------------------------------------
  46.